package com.wlr.littleprogram.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wlr.littleprogram.dao.CpuInfoDao;
import com.wlr.littleprogram.entity.CpuInfo;
import com.wlr.littleprogram.service.SpiderCpuInfoService;
import com.wlr.littleprogram.spider.constant.PcDiyConstant;
import com.wlr.littleprogram.spider.pipeline.ZolCpuPipeline;
import com.wlr.littleprogram.spider.processor.ZolCpuPageProcessor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.Spider;

/**
 * @author lrwang
 * @version 1.0
 * @date 2022/7/23 18:16
 */
@Service
@Slf4j
public class SpiderCpuInfoServiceImpl extends ServiceImpl<CpuInfoDao, CpuInfo> implements SpiderCpuInfoService {


    @Override
    public void executeGetData() {
        Spider.create(new ZolCpuPageProcessor())
                .addUrl(PcDiyConstant.ZOL_PC_CPU)
                .thread(10)
                .run();
    }

    @Override
    public void executeSaveData() {
        Spider.create(new ZolCpuPageProcessor())
                .addUrl(PcDiyConstant.ZOL_PC_CPU)
                .thread(10)
                .addPipeline(new ZolCpuPipeline())
                .run();
    }
}
